package xj.app;

import java.awt.*;
import javax.swing.*;

import static xj.app.BaseApplicationFrame.getResourceString;

public class ClosableFrame 
  extends JFrame { 

  public ClosableFrame(String title) { 
    this(title, null);
  }

  public ClosableFrame(String title, String name) { 
    super(title);
    this.name = name; 
  }

  public ClosableFrame(ClosablePanel cp) { 
    if (cp != null) { 
      name = cp.getName();
      String title = getResourceString(name + ".Panel.title");
      if (title == null) { 
	title = name;
      }
      setTitle(title);

      Container cont = cp.getContentContainer();
      setContentPane(cont);

      Icon icon = cp.getIcon(); 
      if (icon instanceof ImageIcon) { 
	ImageIcon ic = (ImageIcon) icon;
	setIconImage(ic.getImage());
      }

      setAlwaysOnTop(true);

      int width = cp.getDetachedWidth();
      int height = cp.getDetachedHeight(); 
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      int x = screenSize.width / 2 - width / 2;
      int y = screenSize.height / 2 - height / 2;
      setSize(width, height);
      setLocation(x, y);
    }
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  protected String name; 

}